package wnxy.wn44.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import wnxy.wn44.model.Poetry;
import wnxy.wn44.service.PoetryService;

@Controller
@RequestMapping("/test")
public class TestController {

    private PoetryService poetryService;

    @Autowired
    public void setPoetryService(PoetryService poetryService) {
        this.poetryService = poetryService;
    }

    @RequestMapping
    public String doTest(){
        return "test";
    }

    @GetMapping("/request/{id}")
    @ResponseBody
    public Poetry detailRequest(@PathVariable("id")Integer id){
        Poetry poetry = poetryService.findPoetryById(id);
        //--SpringMvc会自动使用Jackson来帮我们完成对象-》字符串的序列化操作！！
        return poetry;
    }
}
